
const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
data: {
          msgs1:[],
	mid:0,
	bid:0,
 xs:'none',

	fsize:12,
	ms:false,
	ys:'',
	bj:'',
},

showModal(message) {
   App.WxService.showModal({
    	title: '友情提示',
    	content: message,
    	showCancel: !1,
   });
},
onShareAppMessage: function () {
},
onLoad(option) {
	if (option){
      this.setData({
         globalOption: option,
		  bid:option.bid,
		  mid:option.id
      })
    }
},
onShow(){
     this.getMsgs1();


	this.setData({
		fsize:wx.getStorageSync("fsize")==''?12:wx.getStorageSync("fsize"),
		ms:wx.getStorageSync("ms")==''?false:wx.getStorageSync("ms"),
		ys:wx.getStorageSync("ys")==''?"":wx.getStorageSync("ys"),
		bj:wx.getStorageSync("bj")==''?"":wx.getStorageSync("bj"),
	})



},
clicks(e) {


	if(this.data.xs=='none')
	{
		this.setData({
			xs:"inline-flex"
		})
	}
	else
	{
		this.setData({
			xs:"none"
		})
	}

},
getMsgs1(){
	  //得到章节内容
      let param = {
      	  f:4,
		  mid:this.data.mid,
		  bid:this.data.bid,
          loadmsg:`正在加载中`
      };

      App.HttpService.getData(param,"/books_List").then(data=>{
		  this.setData({
			  msgs1: data
		  });
      });

      this.baocun();
},
	showModal2(e) {
		this.setData({
			modalName: e.currentTarget.dataset.target
		})
	},
	hideModal(e) {
		this.setData({
			modalName: null
		})
	},

	//左侧目录
	readm(e){
		this.setData({
			mid:e.currentTarget.dataset.id,
			bid:e.currentTarget.dataset.bid,
			modalName: null
		})

		this.getMsgs1();
	},

	//上一张
	shang(e){
		let param = {
			f:5,
			mid:this.data.mid,
			bid:this.data.bid,
			loadmsg:`正在加载中`
		};

		App.HttpService.getData(param,"/books_List").then(data=>{

			if(data.length==0)
			{
				this.showModal("已到第一章");
			}
			else{
				this.setData({
					msgs1: data,
					mid:data[0].mid,
					bid:data[0].bid,
				});
			}

			this.baocun();
		});
	},

	//下一章
	xia(e){
		let param = {
			f:6,
			mid:this.data.mid,
			bid:this.data.bid,
			loadmsg:`正在加载中`
		};

		App.HttpService.getData(param,"/books_List").then(data=>{

			if(data.length==0)
			{
				this.showModal("已到最后一章");
			}
			else{
				this.setData({
					msgs1: data,
					mid:data[0].mid,
					bid:data[0].bid,
				});
			}


			this.baocun();
		});
	},

	//保存阅读记录
	baocun()
	{
		let param = {
			mid:this.data.mid,
			bid:this.data.bid,
			mid2:wx.getStorageSync('mid'),
		};

		App.HttpService.saveData(param,"/mreads_Add").then(data=>{

		});
	},


	moshi(e)
	{
		this.setData({
			ms:e.detail.value
		})

		wx.setStorageSync("ms",this.data.ms);
	},

	jian(e)
	{
		if(this.data.fsize>8)
		{
			this.setData({
				fsize:this.data.fsize-1,
			});

			wx.setStorageSync("fsize",this.data.fsize);
		}
	},
	jia(e)
	{
		this.setData({
			fsize:this.data.fsize+1,
		});

		wx.setStorageSync("fsize",this.data.fsize);
	},
	yanse(e)
	{
		this.setData({
			ys:e.currentTarget.dataset.k
		})

		wx.setStorageSync("ys",this.data.ys);
	},
	yanse2(e)
	{
		this.setData({
			bj:e.currentTarget.dataset.k
		})

		wx.setStorageSync("bj",this.data.bj);
	},



	moren(e)
	{
		wx.setStorageSync('fsize', '');
			wx.setStorageSync('ms', '');
			wx.setStorageSync('ys', '');
			wx.setStorageSync('bj', '');
		this.setData({
			fsize:12,
			ms:false,
			ys:'',
			bj:'',
			modalName: null
		})
	}


})
